//单选按钮
function toggleBtn(btnJq, group){	
	if(btnJq.hasClass('active')){
		return false;
	}else{
		group.find('button.active').removeClass('active');
		group.find('button span.glyphicon-check').addClass('glyphicon-unchecked').removeClass('glyphicon-check');
		
		btnJq.addClass('active');
		btnJq.find('span').removeClass('glyphicon-unchecked').addClass('glyphicon-check');	
		return true;
	}
}

//bootstrap-table公用方法
function getSelections(tableJq, field) {
	return $.map(tableJq.bootstrapTable('getSelections'), function (row) {
		if(field==undefined){
			return row;
		}else{
			return row[field];
		}		
	});
}

function idxFormatter(val,row,index){
	return index+1;
}

function viewFormatter(val, row, index){
	if(!val) val = '';
	if(val && (typeof val == 'string') && val.indexOf('<')!=-1){
		val = '<pre>'+val+'</pre>';
	}else if(typeof val == 'object'){
		val = val;
	}
	if(val && val.length>200){
		val = val.substring(0,200)+'...请点"+"查询完整内容';
	}
	return '<div style="max-width:500px;word-break:break-all;">'+val+'</div>';
}

function detailFormatter(index, row) {
	var html = [];
	$.each(row, function (key, value) {
		html.push('<p><b>' + key + ':</b> ' + value + '</p>');
	});
	return html.join('');
}

var _template = '<div class="tooltip" role="tooltip">'+
				'	<div class="tooltip-arrow" style="border-right-color:#f00;"></div>'+
				'	<div class="tooltip-inner" style="background:#f00;"></div>'+
				'</div>';	

function checkAndGetValues(container, tip){
	var data = {};
	var pass = true;

	container.find(':input').each(function(i,n){
		var jq = $(n);
		var val = '';
		if(jq.is('input') || jq.is('textarea')){
			val = $.trim(jq.val());
			
		}else if(jq.is('select')){
			val = jq.find('option:selected').val();
		}		
		//var reqJq = jq.nextAll('span');
		if(jq.hasClass('required') && val=='' && !jq.attr('disabled')){
			var title = '必填！';
			title=jq.attr('placeholder')?jq.attr('placeholder'):title;
			title=jq.attr('title')?jq.attr('title'):title;
			title=jq.attr('data-tip')?jq.attr('data-tip'):title;

			var placement = jq.attr('data-placement')?jq.attr('data-placement'):'right';
			var template=tip?tip:_template
			template = template.replace('right',placement);

			var tipOpts = {title:title, placement:placement, trigger:'click', template:template};
			jq.tooltip(tipOpts).tooltip('show');
			pass = false;
			return false;
		}
		jq.tooltip('destroy');
		if(val!=''){
			data[jq.attr('id')]=jq.val();
		}
	});
	if(pass==false) return false;

	return data;
}